var page = require('webpage').create();
page.viewportSize = {
  width: 1920,
  height: 800
};
phantom.outputEncodeing = 'utf8';
var system = require('system');
if (system.args.length === 1) {
    console.log('plase import the url and ontput file');
} else {
	var tabUrl = system.args[1];
	var outFile = system.args[2];
    page.open(tabUrl, function(status) {
    	if(status == 'success') {
    		console.log("open url success");
    		var time_Month = new Date().getMonth() + 1;
    		var time_Day = new Date().getDate();
    		//设置背景色，有些网页截图背景色为黑色，同意设置成为白色
    		page.evaluate(function() {
			  document.body.bgColor = 'white';
			});
    		setTimeout(function() {
    			page.render( outFile + '/'+ time_Month + '-' + time_Day +'.jpg');
    			phantom.exit();
    		}, 2000);
    	}else {
    		console.log('can not open');
    		phantom.exit();
    	}
    })
}

